//
//  PaseHTML.m
//  uMeng
//
//  Created by ZhuoLaiQiang@Gmail.com on 6/14/11.
//  Copyright 2011 Mtime. All rights reserved.
//

#import "PaseHTML.h"
#import "Element.h"
#import "DocumentRoot.h"


@implementation PaseHTML

/*
 <form>
 //<input type="hidden" value="✓" name="utf8">
 // <input type="hidden" value="4TVI71QUYV9nvel9uEPMenDnebcDec+9oiciVHMrpvg=" name="authenticity_token"></div>
 
 //<input type="text" value="" size="40" name="user[email]" id="user_mail_new" class="input_205 email">
 
 //<input type="password" value="" size="40" name="user[password]" id="user_password" class="input_205">
 
 //<input type="hidden" value="0" name="user[remember_me]">
 // <input type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
 
 <input type="image" style="" src="/images/new_ui/register/user_signin.jpg" id="login">
 </form>
 */

/*
 authenticity_token	pPuHDY4vHxHC+lTgw/YqZ5QqM7TD5Q0ASXd/pEm90Wk=
 user[email]	497943942@qq.com
 user[password]	0987654321
 user[remember_me]	0
 user[remember_me]	1
 utf8	✓
 
 x	49
 y	19
 */
+ (NSMutableDictionary*)getParametersFromHTML:(NSString*)html
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
    DocumentRoot *rootElement = [Element parseHTML: html];
    NSArray *pA = [rootElement selectElements: @"input"];
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    for (id e in pA) 
    {
        Element *element = (Element*)e;
        NSString *value = [element attribute: @"value"];
        if (value && ![value isEqualToString: @""])
        {
            [dic setObject: value forKey: [element attribute: @"name"]];
        }  
    }
    //这是两个必须的参数
    [dic setObject: @"49" forKey: @"x"];
    [dic setObject: @"19" forKey: @"y"];
    
    [pool release];
    TTDINFO(@"%@",  dic);
    return [dic autorelease];
}

@end
